package com.lxblyw.service;

import java.util.ArrayList;
import java.util.List;

import com.lxblyw.dao.EmployeeDao;
import com.lxblyw.dao.IdeaCommentDao;
import com.lxblyw.dao.IdeaDao;
import com.lxblyw.dao.ProjectDao;
import com.lxblyw.entity.Employee;
import com.lxblyw.entity.Idea;
import com.lxblyw.entity.IdeaComment;
import com.lxblyw.entity.IdeaCommentItem;
import com.lxblyw.entity.IdeaItem;
import com.lxblyw.entity.Project;

public class IdeaService {
	private EmployeeDao emDao = new EmployeeDao();
	private ProjectDao projDao = new ProjectDao();
	private IdeaDao ideaDao = new IdeaDao();
	private IdeaCommentDao commentDao = new IdeaCommentDao();
	public List<IdeaItem> list(String projectid) {
		List<Idea> ideaList =  ideaDao.findByProjectId(projectid);
		List<IdeaItem> ideaItemList = new ArrayList<IdeaItem>();
		
		for(Idea idea : ideaList) {
			Employee employee = emDao.findById(idea.getEmployeeid());
			Project project = projDao.findProjectById(idea.getProjectid());
			IdeaItem ideaItem = new IdeaItem();
			
			ideaItem.setIdea(idea);
			ideaItem.setEmployee(employee);
			ideaItem.setProject(project);
			ideaItemList.add(ideaItem);
		}
		return ideaItemList;
	}
	public List<IdeaCommentItem> getComment(String id) {
		
		List<IdeaComment> commentList = commentDao.findByIdeaId(id);
		List<IdeaCommentItem> commentItemList = new ArrayList<IdeaCommentItem>();
		for(IdeaComment comment : commentList) {
			Employee employee = emDao.findById(comment.getEmployeeid());
			IdeaCommentItem commentItem = new IdeaCommentItem();
			commentItem.setIdeaComent(comment);
			commentItem.setEmployee(employee);
			
			commentItemList.add(commentItem);
		}
		
		return commentItemList;
	}
	public void saveComment(IdeaComment comment) {
		commentDao.save(comment);
	}
	public void delComment(String id) {
		commentDao.delete(id);
	}
	public void save(Idea idea) {
		ideaDao.save(idea);
	}
	public void update(String title, String content, String id) {
		ideaDao.update(title,content,id);
	}
	public void del(String id) {
		ideaDao.delete(id);
	}
	public Idea get(String id) {
		return ideaDao.findById(id);
	}
	
}
